package com.dyna.foundation.feign;

import com.dyna.constants.AppConstant;
import com.dyna.core.config.FeignConfig;
import com.dyna.domain.dto.LoginUser;
import com.dyna.domain.resp.R;
import com.dyna.foundation.domain.entity.SysUser;
import com.dyna.foundation.domain.resp.SysUserResp;
import com.dyna.foundation.failback.FoundationUserFailBack;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author zhoucaiwang
 * @date 2024/3/30
 */
@FeignClient(name = AppConstant.APPLICATION_FOUNDATION_NAME,
        value = AppConstant.APPLICATION_FOUNDATION_NAME,
        fallback = FoundationUserFailBack.class,
        configuration = FeignConfig.class)
public interface FoundationUserApi {

    String USER_PREFIX = "/user";

    @ApiOperation(value = "获得用户详情")
    @GetMapping(USER_PREFIX + "/get")
    R<SysUserResp> getUser(@RequestParam("userId") Long userId);

    @ApiOperation(value = "查询登录用户")
    @RequestMapping(USER_PREFIX + "/getLoginUserById")
    R<LoginUser> getLoginUserById(@RequestParam(value = "userId", required = false) @NotNull(message = "用户id不能为空") Long userId);

    /**
     * 根据用户名查询
     * @param username 用户名
     * @return User
     */
    @RequestMapping(USER_PREFIX + "/getUserByUsername/{username}")
    R<SysUser> getUserByUsername(@PathVariable("username") String username);

    /**
     * 删除用户
     * @param userId 用户id
     * @return Boolean
     */
    @DeleteMapping(USER_PREFIX + "/delete")
    R<Boolean> deleteUser(@RequestParam("userId") Long userId);

    /**
     * 测试远程调用删除用户
     * @param userId 用户id
     * @return Boolean
     */
    @RequestMapping(USER_PREFIX + "/testDel")
    R<Boolean> testDel(@RequestParam("userId") Long userId);

}
